<?php
/**
 * Class Diy
 * Desc  Diy模式
 * Create on 2022/5/18 8:49
 * Create by wangyafang
 */

namespace app\api\controller\wdsxh;



class Diy extends Base
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function mode()
    {
        $conf=$this->configObj;
        $this->success('请求成功',['home_mode'=>$conf['home_mode']]);
    }

    public function getPage()
    {
        $page_id = (int)$this->request->request('page_id');

        if (Db("wdsxh_diy_page")->where(['deletetime' => null])->order(['id' => 'desc'])->count() <= 0) {
            $this->error('未定义页面');
        }
        // 页面详情
        $detail = $page_id > 0 ? Db("wdsxh_diy_page")->where('id', $page_id)->find() : Db("wdsxh_diy_page")->where('status', 'home')->find();
        if (!$detail) {
            $this->error('页面错误');
        }
        $page_data = json_decode($detail['page_data'],true);

        $page_data['domain'] = $this->request->domain();

        // 页面diy元素
        return $this->success('', $page_data);
    }
}